<?php
/**
 * @author song
 */
class Db {

    static private  $instance   =  array();     //  数据库连接实例
    static private  $_instance  =  null;   //  当前数据库连接实例
    /**
     * 取得数据库类实例
     */
    public function getInstance($db_config='db1') {
        if(!isset(self::$instance[$db_config])) {
            $config=C($db_config);
            $class=$config['type'];
            if(empty($class)) $class='Pdohelper';
            if(file_exists(LIB_PATH.'db/'.$class.'.class.php')){
                require_once LIB_PATH.'db/'.$class.'.class.php';
                if(class_exists($class)){
                    self::$instance[$db_config]   =   new $class($config);
                }else{
                    throw new Exception($class.'数据库操作类不存在');
                }
            }else{
                throw new Exception($class.'数据库驱动不存在');
            }
        }
        return self::$instance[$db_config];
    }
}
